package com.yyfax.pay.order.data.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.yyfax.commons.lang.DateUtil;
import com.yyfax.framework.service.CacheService;
import com.yyfax.framework.service.impl.BaseServiceImpl;
import com.yyfax.pay.order.data.dao.PayOrderLogDao;
import com.yyfax.pay.order.data.service.PayOrderLogService;
import com.yyfax.pay.order.model.po.PayOrderLogPO;

/**
 * 支付日志服务实现
 *
 * @author buyi
 * @date 2017-04-12 11:09:15
 * @since 1.0.0
 */
@Service
public class PayOrderLogServiceImpl extends BaseServiceImpl implements PayOrderLogService {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private PayOrderLogDao payOrderLogDao;

	public PayOrderLogServiceImpl(@Qualifier("payCacheService") CacheService cacheService) {
		super(cacheService);
	}

	@Override
	public PayOrderLogPO queryByIdAndMerchantCode(int id, String merchantCode) throws Exception {
		if (id <= 0 && StringUtils.isBlank(merchantCode)) {
			logger.debug("参数 'id' 不能为0，且 'merchantCode' 不能为空 ");
			return null;
		}

		return payOrderLogDao.selectByIdAndMerchantCode(id, merchantCode);
	}

	@Override
	public int save(PayOrderLogPO po) throws Exception {
		if (po == null) {
			logger.debug("参数po为空，返回-1");
			return 0;
		}
		
		po.setCreateTime(DateUtil.getCurrentDateTime());

		return payOrderLogDao.insert(po);
	}

	@Override
	public List<PayOrderLogPO> queryListByPayOrderId(String payOrderId, String merchantCode) throws Exception {
		if (StringUtils.isBlank(payOrderId) && StringUtils.isBlank(merchantCode)) {
			logger.debug("参数 payOrderId/merchantCode 为空 ");
			return null;
		}
		return payOrderLogDao.selectListByPayOrderId(payOrderId, merchantCode);
	}

}
